import { wxRequest } from '../../../utils/server.js';
const _wxRequest = new wxRequest();
const app = getApp()

Page({
  data: {
    datalist: [],
    pageNo: 1,
    pageSize: 200,
    totalSize: 0,
  },

  onLoad: function (options) {
    this.getlist();
  },

  // 获取列表
  getlist: function () {
    var that = this
    _wxRequest.wxTonkenAjax({
      url: app.globalData.apiUrl + "/org/protected/bizOrg/findStoreList",
      method: "post",
      data: {
        keyword: that.data.keywords,
        status: 1,
        pageNo: that.data.pageNo,
        pageSize: that.data.pageSize
      }
    }, function (res) {
      let datalist = that.data.datalist.concat(res.list)
      that.setData({
        datalist: datalist,
        totalSize: res.page.totalSize
      })
    })
  },


  //监听搜索
  seacherOn: function (e) {
    var keywords = e.detail
    this.setData({
      keywords,
      datalist: [],
      pageNo: 1,
      pageSize: 200,
      totalSize: 0,
    })
    this.getlist()
  },


  //选择供应商
  choose: function (e) {
    console.log('choose', e)
    var item = e.currentTarget.dataset.item

    //直接调用上一个页面的setData()方法，把数据存到上一个页面中去
    var pages = getCurrentPages();
    var prevPage = pages[pages.length - 2]; //上一个页面    
    prevPage.setData({
      storeItem: item,
    })
    wx.navigateBack();
  },
  onReachBottom: function () {
    if (this.data.pageNo * this.data.pageSize < this.data.totalSize) {
      this.setData({ pageNo: this.data.pageNo + 1 }, () => {
        this.getlist()
      })
    }
  }

})